package com.zy.web.demo.duoxiancheng.demo16;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/8/17 15:18
 */
public class ThreadB16 extends Thread {

    public static final int INT = 10;
    private Object object;

    public ThreadB16(Object object){
        super();
        this.object = object;
    }

    @Override
    public void run() {
        try {
            synchronized (object){
                for (int i = 0; i < INT; i++) {
                    MyList16.add();
                    if (MyList16.size() == 5){
                        object.notify();
                        System.out.println("发出通知");
                    }
                    System.out.println(Thread.currentThread().getName()+"添加了"+i+"个元素");
                    Thread.sleep(1000);
                }
            }
        }catch (InterruptedException e){
            e.printStackTrace();
        }

    }
}
